package com.company;

import javax.swing.*;
import java.awt.*;

class BackgroundPanel extends JPanel {
    private Image backgroundImage;

    public BackgroundPanel(String imagePath) {
        backgroundImage = new ImageIcon(imagePath).getImage();
        if (backgroundImage.getWidth(null) == -1) {
            System.err.println("无法加载图片: " + imagePath);
        }
    }

    @Override
    protected void paintComponent(Graphics g) {
        super.paintComponent(g);
        // 绘制背景图，铺满整个面板
        g.drawImage(backgroundImage, 0, 0, getWidth(), getHeight(), this);
    }
}